//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_HAL_BITOPS_H__
#define __ELASTOS_HAL_BITOPS_H__

INLINE void SetBit(uint_t uBitNo, volatile byte_t *pb)
{
    pb[uBitNo >> 3] |= __8BIT(uBitNo & 7);
}

INLINE void ClearBit(uint_t uBitNo, volatile byte_t *pb)
{
    pb[uBitNo >> 3] &= ~__8BIT(uBitNo & 7);
}

INLINE void ChangeBit(uint_t uBitNo, volatile byte_t *pb)
{
    pb[uBitNo >> 3] ^= __8BIT(uBitNo & 7);
}

INLINE uint_t TestBit(uint_t uBitNo, volatile byte_t *pb)
{
    return pb[uBitNo >> 3] & __8BIT(uBitNo & 7);
}

INLINE uint_t TestAndChangeBit(uint_t uBitNo, volatile byte_t *pb)
{
    byte_t bBitMask = __8BIT(uBitNo & 7);
    byte_t bOrgByte = pb[uBitNo >> 3];

    pb[uBitNo >> 3] = bOrgByte ^ bBitMask;

    return bOrgByte & bBitMask;
}

#endif // __ELASTOS_HAL_BITOPS_H__
